﻿using System;
using System.IO;
using System.Web.UI.WebControls;
using System.Configuration;
using Medianamik.Core.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;


namespace TypeManagement.Controls
{
    //public class TemplateDropDownList : DropDownList
    //{
    //    protected static MedianamikConfigSection Config = (MedianamikConfigSection)ConfigurationManager.GetSection(Medianamik.Core.ConfigurationSectionName.MEDIANAMIK);
        
    //    public override object DataSource
    //    {
    //        get
    //        {
    //            List<string> templates = new List<string>();
    //            if (!string.IsNullOrEmpty(Config.ClientTemplatePath))
    //            {
    //                string[] paths = Config.ClientTemplatePath.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
                    
    //                foreach (string path in paths)
    //                {

    //                    templates.AddRange(SelectTemplatesRecursive(path));
    //                }
                    
    //            }
    //            return templates;
    //        }
    //        set
    //        {
    //            throw new Exception("Cannot set DataSource of this control");
    //        }
    //    }

    //    public List<String> SelectTemplatesRecursive(string pVirtualPath)
    //    {
    //        List<string> allFiles = new List<string>();
    //        var fullPath = Page.Server.MapPath(pVirtualPath);
    //        DirectoryInfo dir = new DirectoryInfo(fullPath);
    //        if (dir.Exists)
    //        {
    //            var files = dir.GetFiles("*.aspx", SearchOption.TopDirectoryOnly);
    //            allFiles.AddRange(files.Select(f => VirtualPathUtility.AppendTrailingSlash(pVirtualPath) + f.Name));
            
    //            foreach(var subDir in dir.GetDirectories())
    //            {
    //                allFiles.AddRange(SelectTemplatesRecursive(VirtualPathUtility.AppendTrailingSlash(pVirtualPath) + subDir.Name));
    //            }
    //        }

    //        return allFiles;
    //    }

    //    protected override void OnDataBound(EventArgs e)
    //    {
    //        base.OnDataBound(e);
    //        Items.Insert(0, string.Empty);
    //    }
    //}
}
